<template>
    <div>
        获取验证码{{ time }}s
    </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue';
//定义倒计时时间
let time = ref(5)

// 接受flag
let props = defineProps(['flag']);
let $emit = defineEmits(['getFlag'])

watch(() => props.flag, () => {
    let timer = setInterval(() => {
        time.value--;
        if (time.value == 0) {
            $emit('getFlag', false)
            clearInterval(timer)
        }
    }, 1000);

}, { immediate: true })
</script>

<style scoped></style>